<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>批量支付登记</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">


        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>关联流程</th>
                            <th>款项类型</th>
                            <th>工程名称</th>
                            <th>款项说明</th>
                            <th>请款金额(元)</th>
                            <th>支付方式</th>
                            <th>付款对象</th>
                            <th>账户</th>
                            <th>账号</th>
                            <th>开户行</th>
                            <th>已付金额(元)</th>
                            <th>未付金额(元)</th>
                            <th><text>*</text>本次支付金额(元)</th>
                            <th><text>*</text>支付账户</th>
                            <th><text>*</text>交易日期</th>
                            <th><text>*</text>经手人</th>
                            <th>备注</th>
                            <th>附件</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>


    </div>
</form>
<script>
    var param_ids = getQueryVariable('ids') || '';


    function choose_account(obj){
        var domkey = $(obj).parents('tr').index();
        openPage('../public/choose_account.php?page=account_list_mulpay&domkey='+domkey,'80%','80%');
    }


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();
        facade.ajax({type: 'get', url: ask_account_list_mulpay, data:{ids:param_ids}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;


                short_table_opt_func('', 1);

                var list = res.data.list;
                if(list.length > 0){
                    var str = '';
                    for (var key in list){
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><input type="text" class="layui-input sericnum disabled" kuanid="'+list[key].id+'" readonly value="'+list[key].bill.sericnum+'"></td>';
                        str += '<td><input type="text" class="layui-input kuanlei disabled" readonly value="'+list[key].kuanlei+'"></td>';
                        str += '<td><input type="text" class="layui-input enginname disabled" readonly value="'+list[key].enginname+'"></td>';
                        str += '<td><input type="text" class="layui-input zhai disabled" readonly value="'+list[key].zhai+'"></td>';
                        str += '<td><input type="text" class="layui-input jiaomoney disabled" readonly value="'+list[key].money+'"></td>';
                        str += '<td><input type="text" class="layui-input incdaotype disabled" readonly value="'+list[key].incdaotype+'"></td>';
                        str += '<td><input type="text" class="layui-input duier disabled" readonly value="'+list[key].duier+'"></td>';
                        str += '<td><input type="text" class="layui-input bankzhang disabled" readonly value="'+list[key].bankzhang+'"></td>';
                        str += '<td><input type="text" class="layui-input banknum disabled" readonly value="'+list[key].banknum+'"></td>';
                        str += '<td><input type="text" class="layui-input bankname disabled" readonly value="'+list[key].bankname+'"></td>';
                        str += '<td><input type="text" class="layui-input payfee disabled" readonly value="'+list[key].payfee+'"></td>';
                        str += '<td><input type="text" class="layui-input nofee disabled" readonly value="'+list[key].nofee+'"></td>';
                        str += '<td><input type="number" class="layui-input money" value="'+list[key].nofee+'"></td>';
                        str += '<td><input type="text" class="layui-input accid" onclick="choose_account(this)" readonly placeholder="请选择"></td>';
                        str += '<td><input type="text" class="layui-input dt bdate_ymd" readonly value="'+res.data.dt+'"></td>';
                        str += '<td><input type="text" class="layui-input baner" value="'+res.data.baner+'"></td>';
                        str += '<td><input type="text" class="layui-input explain"></td>';
                        str += '<td>'+public_show_file_deta('list_list', [],1)+'</td>';
                        str += '</tr>';
                    }
                    $("#list_list").html(str);
                }
                update_refresh_row_func();



                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });



        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}

            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var kuanid = $(this).find('.sericnum').attr('kuanid') || 0;
                    var money = $(this).find('.money').val();
                    var accid = $(this).find('.accid').attr('key') || 0;
                    var dt = $(this).find('.dt').val();
                    var baner = $(this).find('.baner').val();
                    var explain = $(this).find('.explain').val();
                    var files = public_deta_file_value(this);

                    var index = i + 1;

                    if(money == ''){
                        throw new Error('第'+index+'行，请输入本次支付金额');
                    }
                    if(!accid){
                        throw new Error('第'+index+'行，请选择支付账户');
                    }
                    if(!dt){
                        throw new Error('第'+index+'行，请选择交易日期');
                    }
                    if(!baner){
                        throw new Error('第'+index+'行，请输入经手人');
                    }

                    list.push({
                        kuanid:kuanid,
                        money:money,
                        accid:accid,
                        dt:dt,
                        baner:baner,
                        explain:explain,
                        files:files
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;


            data = parseMoney(data);

            facade.ajax({url: ask_account_list_mulpay, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });
            return false;
        });

    });







    function update_refresh_row_func() {
        render_date();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });

        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }







</script>
</body>
</html>
